﻿@inject NavigationManager Navigation

<nav class="topnav navbar navbar-expand-lg navbar-dark bg-primary fixed-top @NavClass">
    <div class="container">
        <Logo/>
        <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse" id="navbarColor02" style="">
            <ul class="navbar-nav mr-auto d-flex align-items-center">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">项目</a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        @foreach (var project in _projects)
                        {
                            <a class="dropdown-item" href="@project.Value" target="_blank">
                                @project.Key
                            </a>
                        }
                    </div>
                </li>
                <li class="nav-item@(IsActive("/doc") ? " active" : "")">
                    <a class="nav-link" href="/doc">文档</a>
                </li>
                <li class="nav-item@(IsActive("/bbs") ? " active" : "")">
                    <a class="nav-link" href="/bbs">博文</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">关于</a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        @foreach (var resource in _resources)
                        {
                            <a class="dropdown-item" href="@resource.Value" target="_blank">@resource.Key</a>
                        }
                    </div>
                </li>
            </ul>
            <ul class="navbar-nav ml-auto d-flex align-items-center">
                <li class="nav-item">
                    <span class="nav-link">
                        <a class="btn btn-success btn-round shadow-sm" href="https://github.com/dotnet9/CodeWF" target="_blank">
                            Github
                        </a>
                    </span>
                </li>
            </ul>
        </div>
    </div>
</nav>

@code {
    private string NavClass => IsIndex ? "index-nav" : DarkNavClass;
    public const string DarkNavClass ="bg-white navbar-light shadow-sm scrollednav";

    private Dictionary<string, string> _projects = new()
    {
        { "CodeWF", "https://github.com/dotnet9/CodeWF" },
        { "CodeWF.EventBus", "https://github.com/dotnet9/CodeWF.EventBus" },
        { "CodeWF.EventBus.Socket", "https://github.com/dotnet9/CodeWF.EventBus.Socket" },
        { "CodeWF.NetWeaver", "https://github.com/dotnet9/CodeWF.NetWeaver" },
        { "CodeWF.Toolbox", "https://github.com/dotnet9/CodeWF.Toolbox" },
        { "CodeWF.Tools", "https://github.com/dotnet9/CodeWF.Tools" },
        { "Assets.Dotnet9", "https://github.com/dotnet9/Assets.Dotnet9" }
    };

    private Dictionary<string, string> _resources = new()
    {
        { "赞助", "/donation" },
        { "博客园", "https://www.cnblogs.com/Dotnet9-com" },
        { "B站", "https://space.bilibili.com/470546606" },
        { "关于", "/about" }
    };

    [Parameter] public bool IsIndex { get; set; }

    private bool IsActive(string code)
    {
        var uri = Navigation.Uri.Replace(Navigation.BaseUri, "/");
        return uri.StartsWith(code);
    }

}
